﻿<UserControl x:Class="iTFF.WPF.View.ArtworksView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:l="clr-namespace:iTFF.WPF.Resources.Languages"
    xmlns:ui="clr-namespace:iTFF.WPF.UI">
  <UserControl.Resources>
    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
    <ui:NotBooleanConverter x:Key="NotBooleanConverter" />
  </UserControl.Resources>

  <Border Style="{StaticResource tabItemBorderStyle}">
    <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>

      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>

      <Button Grid.Row="0" Grid.Column="0" Command="{Binding FromiTunesCommand}" Margin="4">
        <StackPanel Orientation="Horizontal">
          <TextBlock Text="{x:Static l:Strings.ArtworkViewFromiTunes}" Margin="2" />
          <Image Source="../Resources/Images/bullet_go.png" Margin="2" />
        </StackPanel>
      </Button>

      <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding SearchText, UpdateSourceTrigger=PropertyChanged}" Margin="4" />

      <Button Grid.Row="0" Grid.Column="2" Content="{x:Static l:Strings.ArtworkViewSearch}" Margin="4" Padding="2" Command="{Binding SearchCommand}" />
      <Button Grid.Row="0" Grid.Column="2" Content="{x:Static l:Strings.Cancel}" Margin="4" Padding="2" Command="{Binding CancelSearchCommand}" 
              Visibility="{Binding IsSearching, Converter={StaticResource BooleanToVisibilityConverter}}" />

      <ProgressBar Grid.Row="1" Grid.ColumnSpan="3" Value="{Binding ProgressBarValue}" Minimum="0" Maximum="100" Height="30" Margin="4" 
                   IsIndeterminate="{Binding IsSearching}"
                   Visibility="{Binding IsSearching, Converter={StaticResource BooleanToVisibilityConverter}}" />

      <ScrollViewer Grid.Row="2" Grid.ColumnSpan="3" VerticalScrollBarVisibility="Auto">
        <Grid>
          <ItemsControl ItemsSource="{Binding Artworks}" Margin="4">
            
            <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                <WrapPanel IsItemsHost="True" />
              </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>

            <ItemsControl.ItemTemplate>
              <DataTemplate>

                <Grid>

                  <Button Margin="2" Height="160" Command="{Binding ApplyCommand}" 
                          IsEnabled="{Binding IsApplyingAnotherArtwork, Converter={StaticResource NotBooleanConverter}}" >
                    <Grid Margin="2">
                      <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="115" />
                      </Grid.ColumnDefinitions>

                      <Image Width="130" Height="130" Margin="10" Source="{Binding ImageURLMedium}" />

                      <StackPanel Grid.Column="1">
                        <!--- Artist -->
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="{x:Static l:Strings.Artist}" FontStyle="Italic" />
                          <TextBlock Text=" : " FontStyle="Italic" />
                        </StackPanel>
                        <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Artist}" FontWeight="Bold" />

                        <!--- Album -->
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="{x:Static l:Strings.Album}" FontStyle="Italic" />
                          <TextBlock Text=" : " FontStyle="Italic" />
                        </StackPanel>
                        <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding Album}" FontWeight="Bold" />

                        <!--- Realease date -->
                        <StackPanel Orientation="Horizontal">
                          <TextBlock Text="{x:Static l:Strings.ArtworksViewReleaseDate}" FontStyle="Italic" />
                          <TextBlock Text=" : " FontStyle="Italic" />
                        </StackPanel>
                        <TextBlock TextWrapping="WrapWithOverflow" Text="{Binding ReleaseDate}" FontWeight="Bold" />

                      </StackPanel>
                    </Grid>
                  </Button>

                  <Border HorizontalAlignment="Center" VerticalAlignment="Center"
                          Visibility="{Binding IsApplyingArtwork, Converter={StaticResource BooleanToVisibilityConverter}}"
                          Background="CadetBlue" CornerRadius="5" BorderBrush="Black" BorderThickness="1">
                    <Grid Margin="5" Width="120">
                      <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                      </Grid.RowDefinitions>

                      <ProgressBar Grid.ColumnSpan="3" Value="{Binding ProgressBarValue}" Minimum="0" Maximum="100" Height="20" />

                      <Button Grid.Row="1" Height="40" Content="{x:Static l:Strings.Cancel}" Command="{Binding CancelCommand}">
                        <Button.Background>
                          <LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
                            <GradientStop Offset="0" Color="Coral" />
                            <GradientStop Offset="1" Color="Crimson" />
                          </LinearGradientBrush>
                        </Button.Background>
                      </Button>
                    </Grid>
                  </Border>


                </Grid>
              </DataTemplate>
            </ItemsControl.ItemTemplate>
          </ItemsControl>
        </Grid>
      </ScrollViewer>

      <GroupBox Grid.Row="3" Grid.ColumnSpan="3" Header="Options" Margin="4">

        <StackPanel>
          <CheckBox Content="{x:Static l:Strings.ArtworksViewStoreMinimizedImage}" IsChecked="{Binding StoreMinimizedImage}" Margin="2" />
          <CheckBox Content="{x:Static l:Strings.ArtworksViewApplyAlbums}" IsChecked="{Binding ApplyAlbums}" Margin="2" />
        </StackPanel>

      </GroupBox>

    </Grid>
  </Border>
</UserControl>
